package com.stone.sys.action;

/**
 * <pre>
 * 日志查询Action
 * @author jz
 * </pre>
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.opensymphony.xwork2.Action;
import com.stone.common.action.AdvanceSearchJsonUtils;
import com.stone.sys.pojo.TDictionary;
import com.stone.sys.service.DictionaryService;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;
import frm.ssh.exception.AppException;

public class DictionaryListAction extends BaseListAction {

	private static final long serialVersionUID = 3979577965804736350L;

	private DictionaryService dicService;
	
	public DictionaryService getDicService() {
		return dicService;
	}

	public void setDicService(DictionaryService dicService) {
		this.service = dicService;
		this.dicService = dicService;
	}
	
    /** * 构造方法. */
    public DictionaryListAction() {
        this.entityClass = TDictionary.class;
    }

	/**
	 * 设置查询条件
	 */
	public HashMap<String, Object> setSearchCondition() {
		
		HashMap<String, Object> m = new HashMap<String, Object>();
		
		List<Object> valsList = new ArrayList<Object>();
		
		m.put("cols", "dic");
		
		String conditions = "";
		
		if (super.getRequest().getParameter("type") != null) {
			conditions = " dic.itemType = '" + super.getRequest().getParameter("type") + "'";
			super.getSearchBean().setCon1(super.getRequest().getParameter("type"));
		} else {
			conditions = " dic.itemType = '" + super.getSearchBean().getCon1() + "'";
		}	
		
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())) {
			conditions += " and dic.itemId like ?";
			valsList.add("%" + super.getSearchBean().getCon2() + "%");
		//	conditions += " and dic.itemId like '%" + super.getSearchBean().getCon2() + "%'";
		}
		
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3())) {
			conditions += " and dic.itemName like ?";
			valsList.add("%" + super.getSearchBean().getCon3() + "%");
			//conditions += " and dic.itemName like '%" + super.getSearchBean().getCon3() + "%'";
		}
		
		// 高级查询设置
		try {
			if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getConAdvance())) {
				HashMap<String,Object> rtnMap = AdvanceSearchJsonUtils.jsonToList(super.getSearchBean().getConAdvance());
				conditions += rtnMap.get("conditions");
				valsList.addAll((List<Object>)rtnMap.get("vals"));
			}	
		} catch (Exception e) {
			
		}
		
		// 查询条件
		m.put("conditions",conditions);
		m.put("clause", " order by dic.sortid");
		m.put("alias", "dic");
		m.put("vals", valsList.toArray());
		
		dicList = dicService.findListByHql( " from TDicType order by sortid");
		
		return m;
		
	}
	
	private List<TDictionary> dicList;
	
	/**
	 * 获取值班记录类型字典并进入值班记录frame.jsp
	 * @return
	 * @throws AppException
	 */
	public String initFrame() throws AppException {
		
		dicList = dicService.findList("ZBJLLX");
		
		return Action.SUCCESS;
		
	}

	public List<TDictionary> getDicList() {
		return dicList;
	}
}
